package org.dfg.corejava.designPattern.thread.lock;

import java.util.concurrent.locks.ReentrantLock;

public class Interruptibly {
	private ReentrantLock lock = new ReentrantLock();

	private void write() {
		lock.lock();
		try {
			int i = 2;
			while (1 < i) {

			}
			System.out.println("写完了");
		} catch (Exception e) {
		} finally {
			lock.unlock();
		}

	}

	private void read() throws InterruptedException {
		lock.lockInterruptibly();
		try {
			System.out.println("读完了");
		} catch (Exception e) {
		} finally {
			lock.unlock();
		}
	}
}
